<template>
  <div :class="className" :style="{height:height,width:width}" />
</template>

<script>
import * as echarts from 'echarts'
require('echarts/theme/macarons') // echarts theme
import resize from './mixins/resize'

export default {
  mixins: [resize],
  props: {
    className: {
      type: String,
      default: 'charts'
    },
    width: {
      type: String,
      default: '100%'
    },
    height: {
      type: String,
      default: '100%'
    }
  },
  data() {
    return {
      chart: null,
      colorList: ['#3C7EFF','#C7E1FF']
    }
  },
  mounted() {
    this.$nextTick(() => {
      this.initChart()
    })
  },
  beforeDestroy() {
    if (!this.chart) {
      return
    }
    this.chart.dispose()
    this.chart = null
  },
  methods: {
    initChart() {
      this.chart = echarts.init(this.$el, 'macarons')

      this.chart.setOption({
        title: {
          text: '80.6%',
          x: 'center',
          y: 'center',
          textStyle: {
            fontSize: 18,
            fontWeight: "bold",
            color:'#2A3A77'
          }
        },
        // tooltip: {
        //   trigger: 'item',
        //   formatter: '{a} <br/>{b} : {c} ({d}%)'
        // },
        legend: {
          left: 'center',
          bottom: '10',
          data: ['Industries', 'Technology', 'Forex', 'Gold', 'Forecasts']
        },
        series: [
          {
            type: 'pie',
            center: ['50%', '50%'],
            radius: ['84%', '72%'],
            clockwise: false,
            avoidLabelOverlap: false,
            hoverOffset: 0,
            itemStyle: {
              normal: {
                color: (params) => {
                  return this.colorList[params.dataIndex]
                }
              }
            },
            label: {
              show: false,
            },
            labelLine: {
              normal: {
                length: 20,
                length2: 30,
                lineStyle: {
                    width: 6
                }
              }
            },
            data: [
              {
                'name': '一月',
                'value':80
              },
              {
                'name': '一月',
                'value': 20
              }
            ]
          }
        ]
      })
    }
  }
}
</script>
